//
//  CusTabBarViewController.m
//  cusTabbarText
//
//  Created by xingshuai on 2020/9/28.
//

#import "CusTabBarViewController.h"

#import "CusTabView.h"
#import "ViewController.h"
#import "TwoViewController.h"
#import "ThreeViewController.h"

///屏幕尺寸
#define SCREEN_SIZE  ([[UIScreen mainScreen] bounds].size)
#define ScreenHeight [UIScreen mainScreen].bounds.size.height
#define ScreenWidth  [UIScreen mainScreen].bounds.size.width

@interface CusTabBarViewController () <ClickTabBarDelegate>

@property (nonatomic, strong) CusTabView *tabView;

@end

@implementation CusTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.tabBar.subviews enumerateObjectsUsingBlock:^(__kindof UIView * obj, NSUInteger idx, BOOL * stop) {
          if ([obj isKindOfClass:[UIControl class]]) {
              [obj setHidden:YES];
          }
    }];
    
    self.tabBar.hidden = YES;
    
    [self creatControllers];
    
    [self.view addSubview:self.tabView];
    
}

-(CusTabView *)tabView {
    if (!_tabView) {
        
        CGFloat H = 0;
        
        if ([self getIsIpad]) {
            H = 65;
        } else {
            if (ScreenHeight >= 812) {
                H = 83;
            } else {
                H = self.tabBar.frame.size.height;
            }
        }
        
        _tabView = [[CusTabView alloc]initWithFrame:CGRectMake(0, ScreenHeight-H, self.view.frame.size.width, H)];
        _tabView.backgroundColor = [UIColor blackColor];
        _tabView.delegate = self;
        self.tabBarController.tabBar.backgroundColor = [UIColor clearColor];
    }
    return _tabView;
}

-(void)creatControllers {
    ViewController *oneVC = [[ViewController alloc]init];
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:oneVC];
    
    TwoViewController *twoVC = [[TwoViewController alloc]init];
    UINavigationController *nav1 = [[UINavigationController alloc]initWithRootViewController:twoVC];
    
    ThreeViewController *threeVC = [[ThreeViewController alloc]init];
    UINavigationController *nav2 = [[UINavigationController alloc]initWithRootViewController:threeVC];
    
    self.viewControllers = @[nav,nav1,nav2];
    
}

- (void)clickBtnTag:(NSInteger)btnTag {
    self.selectedIndex = btnTag;
}

//如果想要判断设备是ipad，要用如下方法
- (BOOL)getIsIpad {
    NSString *deviceType = [UIDevice currentDevice].model;
    if([deviceType isEqualToString:@"iPhone"]) {
        //iPhone
        return NO;
    } else if ([deviceType isEqualToString:@"iPod touch"]) {
        //iPod Touch
        return NO;
    } else if ([deviceType isEqualToString:@"iPad"]) {
        //iPad
        return YES;
    }
    return NO;
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/




@end
